﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using Portal.Environment;
using Portal.Language;
using Portal.Interface;

namespace Portal.CMS
{
    public class AddGroupNews : WebPart
    {
        public override string WebPartId
        {
            get
            {
                return "AddGroupNews";
            }
        }

        public override string Title
        {
            get
            {
                return ResourceBLL.GetText(WebPartId,"Title","Thêm mới nhóm");
            }
        }

        public override string Description
        {
            get
            {
                return ResourceBLL.GetText(WebPartId,"Description","");
            }
        }


        public override string RenderWebPart(LoadParamCls loadParamCls)
        {
            AjaxPro.Utility.RegisterTypeForAjax(typeof(AddGroupNews));
            string belongSite = (string)Environments.Request("belongSite");
            string RetHtml =
                WebPartUtilities.AttachJavascript("Portal.CMS", "GroupNews.js") +
                             Environments.GetFormDialog(
                             "<input id=txtBelongSite type=hidden value=\"" + belongSite + "\">" +
                             "      <table>" +
                             "          <tr>" +
                             "              <td>" + ResourceBLL.GetText(WebPartId, "AddGroupNewsCaption", "Thêm tin tức") + "</td>" +
                             "              <td><input class=cssTextBoxDialog id=txtGroupNews></td>" +
                             "          </tr>" +
                             "          <tr>" +
                             "              <td>" + ResourceBLL.GetText(WebPartId, "IsNews", "Nhóm tin") + "</td>" +
                             "              <td><input type=checkbox id=chkIsNews></td>" +
                             "          </tr>" +
                             "          <tr>" +
                             "              <td></td>" +
                             "              <td>(*)"+ResourceBLL.GetText(WebPartId,"Help","Tích vào nhóm tin nếu đây là folder chứa tin tức")+"</td>" +
                             "          </tr>" +
                             "          <tr>" +
                             "              <td></td>" +
                             "              <td><input type=button class=cssSaveButton onclick=javascript:ClientSaveAddGroupNews(); value=\"" + ResourceBLL.GetText(WebPartId, "AddGroupNewsSaveButton", "Ghi lại") + "\"><input type=button class=cssCancelButton onclick=javascript:window.close(); value=\"" + ResourceBLL.GetText(WebPartId, "AddGroupNewsCancelButton", "Thoát") + "\"></td>" +
                             "          </tr>" +
                             "      </table>", ResourceBLL.GetText(WebPartId, "AddGroupNewsFormTitle", "Thêm mới nhóm tin tức"));
            return RetHtml;
        }

        [AjaxPro.AjaxMethod]
        public string ServerSideAddGroupNews(string belongSite, string GroupNewsName, bool IsNews)
        {
            try
            {
                Environment.Environments.CheckSessionTimeOut(true);
                if (GroupNewsName.Trim().Length == 0) throw new Exception(ResourceBLL.GetText(WebPartId,"EnterName","Nhập tên nhóm"));
                string GroupNewsId = new GroupNewsBLL().AddGroupNews(null, belongSite, GroupNewsName, IsNews?1:0);
                return ResourceBLL.GetText(WebPartId,"MessageAddOk","Thêm thành công!");
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }
    }
}